/*
 * Copyright (c) 2007-2020 西安交通信息投资营运有限公司 版权所有
 * 作者:马星俊
 */

import React, {FC, SetStateAction, useEffect, useState} from "react";
import styles from "./Authorize.less";
import {Tree} from "antd";
import permissionService from "@/pages/sys/permission/service";

interface TreeStructureProps {
  /** 数据主键 */
  primaryKey?: string;
}


const Module: FC<TreeStructureProps> = (props) => {
  const {primaryKey} = props;
  const [treeData, setTreeData] = useState<SetStateAction<any>>([]);

  useEffect(() => {
    permissionService.selectRoleModule(primaryKey).then(r => {
      setTreeData(r.data);
    });
  }, [])

  return (
    <div style={{margin: '0 24px 0 0'}}>
      {treeData.length ? (
        <Tree
          style={{maxHeight: '300px', padding: "10px 5px", overflowY: 'auto'}}
          showIcon
          treeData={treeData}
        />
      ) : (<div className={`${styles.alert} ${styles.warning} ${styles.margin} ${styles.padding}`}>未配置</div>)}
    </div>
  )
}

export default Module;
